//
//  ZYSetTableViewController.m
//  ZYOils
//
//  Created by 段新瑞 on 2019/9/24.
//  Copyright © 2019 Mr.Xr. All rights reserved.
//

#import "ZYSetTableViewController.h"

#import "ZYSetContentView.h"
#import "ZYAboultMeViewController.h"
#import "ZYChangePhoneNumViewController.h"
#import "ZYLoginViewController.h"

@interface ZYSetTableViewController ()

@property(nonatomic, strong) UIScrollView *scrollView;

@property(nonatomic, strong) UIView *contentView;

/// 功能区父视图
@property(nonatomic, strong) ZYSetContentView *funcContentView;

@end

@implementation ZYSetTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self.view addSubview:self.scrollView];
    [self customUI];
    
    @weakify(self)
    [self.funcContentView.subject subscribeNext:^(NSNumber *sender) {
        @strongify(self)
        if ([sender isEqualToNumber:@1]) {
            ZYChangePhoneNumViewController *controller = [[ZYChangePhoneNumViewController alloc] initWithNibName:@"ZYChangePhoneNumViewController" bundle:nil];
            controller.title = @"修改手机号";
            [self.navigationController pushViewController:controller animated:YES];
        } else if ([sender isEqualToNumber:@2]) {
            ZYAboultMeViewController *controller = [ZYAboultMeViewController new];
            controller.title = @"关于我们";
            [self.navigationController pushViewController:controller animated:YES];
        } else if ([sender isEqualToNumber:@3]) {
            [ZYUserInfoModel clean];
            ZYLoginViewController *controller = [ZYLoginViewController new];
            NSMutableArray *vcLists = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
            [vcLists removeAllObjects];
            [vcLists addObject:controller];
            [self.navigationController setViewControllers:vcLists animated:NO];
            
            NSLog(@"退出登录");
        }
    }];
    
}

- (void)customUI {
    [self.scrollView addSubview:self.contentView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
        make.width.equalTo(self.scrollView);
        make.height.mas_equalTo(self.scrollView.mas_height).offset(-IPX_STATUSBAROFFSETHEIGHT);
    }];
    
    [self.contentView addSubview:self.funcContentView];
    [self.funcContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(7);
        make.right.mas_equalTo(-7);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(55 * 3 + 10);
    }];
}

- (UIScrollView *)scrollView {
    if (_scrollView == nil) {
        _scrollView = [UIScrollView new];
    }
    return _scrollView;
}

- (UIView *)contentView {
    if (_contentView == nil) {
        _contentView = [UIView new];
    }
    return _contentView;
}

- (ZYSetContentView *)funcContentView {
    if (_funcContentView == nil) {
        _funcContentView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZYSetContentView class]) owner:nil options:nil] lastObject];
        _funcContentView.backgroundColor = [UIColor clearColor];
    }
    return _funcContentView;
}



@end
